package com.superb.system.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.superb.common.database.annotation.DelInterceptorIgnore;
import com.superb.common.database.mybatis.mapper.SuperbMapper;
import com.superb.system.api.entity.SystemTenant;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 系统租户管理表;(system_tenant)表数据库访问层
 * @Author: ajie
 * @CreateTime: 2024-5-11
 */
@Mapper
public interface SystemTenantMapper extends SuperbMapper<SystemTenant> {

    /**
     * 获取索引
     * @param table 表
     * @param column 字段
     * @return
     */
    @DelInterceptorIgnore
    @InterceptorIgnore(tenantLine = "true")
    @Select("SELECT INDEX_NAME FROM information_schema.STATISTICS WHERE TABLE_NAME = #{table} AND COLUMN_NAME = #{column} LIMIT 1")
    String getIndex(@Param("table") String table, @Param("column") String column);

    /**
     * 获取是否存在字段
     * @param table 表
     * @param column 字段
     * @return
     */
    @DelInterceptorIgnore
    @InterceptorIgnore(tenantLine = "true")
    @Select("SELECT COUNT(1) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = #{table} AND COLUMN_NAME = #{column}")
    Boolean getExistColumn(@Param("table") String table, @Param("column") String column);
}